package ui.activity;

import java.util.Random;

import ui.activity.card.CardListActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lab107team.R;

public class WelcomeActivity extends Activity {
	private static final int[] WELCOME_BG = { R.drawable.welcome_bg_1 };
	private static final int[] WELCOME_TITLE = { R.drawable.welcome_title_1 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_welcome);
		// 设置开场动画
		AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
		animation.setDuration(2000);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {

				Intent intent = new Intent(WelcomeActivity.this,
						CardListActivity.class);
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.zoom_out_enter,
						R.anim.zoom_out_exit);
			}
		});
		Random random = new Random();
		int index = random.nextInt(WELCOME_BG.length);
		ImageView imageTitle = (ImageView) findViewById(R.id.welcome_title);
		imageTitle.setAnimation(animation);
		imageTitle.setBackgroundResource(WELCOME_TITLE[index]);
		RelativeLayout rlBackground = (RelativeLayout) findViewById(R.id.welcome_bg);
		rlBackground.setBackgroundResource(WELCOME_BG[index]);
	}
}
